<template>
  <el-form>
    <el-form-item style="margin-top:20px ">
      <el-input v-model="form.username" placeholder="请输入用户名" :prefix-icon="User" size="large" >
      </el-input>
    </el-form-item>
    <el-form-item>
      <el-input v-model="form.password" show-password placeholder="请输入密码"  :prefix-icon="Lock" size="large">
      </el-input>
    </el-form-item>
    <el-form-item>
      <el-button @click="onSubmit()" style="width: 100%" type="primary">登录</el-button>
      <br>
      <el-row justify="space-between" style="width: 100%">
        <el-col :span="3">
          <el-checkbox label="记住我" size="large"></el-checkbox>
        </el-col>
        <el-col :span="6" style="margin-top: 1px">
          <el-link>忘记密码？</el-link>
        </el-col>
      </el-row>
    </el-form-item>
  </el-form>
</template>

<script>
import {login} from "@/api/login";
import router from "@/router/router"
import {ElMessage} from "element-plus";

export default {
  name: "UserLogin",
  data() {
    return {
      form:{
        username:'',
        password:''
      }
    }
  },
  methods:{
    async onSubmit() {
      const t = await login(this.form);
      if (t.data.code === 200) {
        ElMessage({
          type:'success',
          message:'欢迎回来!'
        })
        sessionStorage.setItem('username',this.form.username)
        sessionStorage.setItem('token',t.data.data)
        await router.push('/admin')
      }
    }
  }
}
</script>
<script setup>
import {Lock,User} from "@element-plus/icons-vue";
</script>
<style scoped>
.el-form-item{
  margin-bottom: 40px;
}
</style>